package com.study.project.config.exception;


/**
 * @author Administrator
 */
public interface ErrorCode {
    ErrorCode SUCCESS = new Default("000", "ok");
    ErrorCode REMOTE_INVOKE_ERROR = new Default("500", "服务调用错误");
    ErrorCode TODAY_ALREADY_RECEIVE = new Default("1006", "今日已领取");
    ErrorCode BENEFIT_ALREADY_RECEIVE = new Default("1007", "您已经领取过该权益");
    ErrorCode NOT_FOUND_JOIN_RECORD = new Default("1008", "找不到活动参与记录");
    ErrorCode NOT_FOUND_ACTIVITY_CONF = new Default("1009", "找不到活动配置");
    ErrorCode NOT_FOUND_VALID_CARD_RECORD = new Default("1010", "找不到有效的开卡记录");
    ErrorCode ACTIVITY_NOT_ENABLE = new Default("1011", "活动未启用");
    ErrorCode AWARD_NOT_IN_SEND_TIME_SCOPE = new Default("1012", "未到发放时间哦~");
    ErrorCode ACTIVITY_OVERDUE = new Default("1013", "活动已过期");
    ErrorCode CARD_TIME = new Default("1014", "参数错误,未传权益卡开卡或过期时间");
    ErrorCode NO_LOCK = new Default("LOCK10001", "系统忙(LOCK)");
    ErrorCode NO_ACTIVITY = new Default("1017", "未查询到活动信息");
    ErrorCode REMOTE_INVOKE_MEMBER_ERROR = new Default("1018", "服务会员调用错误");
    ErrorCode NOT_FOUND_ACTIVITY_RULE = new Default("1021", "找不到活动规则配置");
    ErrorCode FREE_COUPON_JOIN_TIMES = new Default("1023", "已超过活动最大领取次数");
    ErrorCode STOCK_ERROR = new Default("1021", "占用库存不能小于单人单次领取数量");
    ErrorCode STOCK_TOTAL_ERROR = new Default("1022", "占用库存不能大于总库存");
    ErrorCode UPDATE_ERROR = new Default("1023", "保存异常");
    ErrorCode RULE_ERROR = new Default("1025", "会员日规则异常");

    String getCode();

    String getMsg();

    default boolean is(String code) {
        return this.getCode().equals(code);
    }

    default boolean is(ErrorCode error) {
        return error != null && this.is(error.getCode());
    }

    static boolean isSuccess(String code) {
        return SUCCESS.is(code);
    }

    class Default implements ErrorCode {
        private final String code;
        private final String msg;

        @Override
        public String getCode() {
            return this.code;
        }

        @Override
        public String getMsg() {
            return this.msg;
        }

        public Default(final String code, final String msg) {
            this.code = code;
            this.msg = msg;
        }
    }
}
